#include <hellomake.h>

#if 0
int main() {
  // call a function in another file
  myPrintHelloMake();

  return(0);
}
#endif

#if 0
#include <stdio.h>
#include <stdlib.h>
 /* 定义一个结构体，里面有三个成员，是三个函数指针 ,前面千万不要加static,这里并没有分配内存*/
struct prt_fn {
    int (*add) (int a, int b);
    int (*sub) (int a, int b);
    int (*mult) (int a, int b);
};


static int add(int a, int b)
{
    return a + b;
}

static int sub(int a, int b)
{
    return a - b;
}

static int mult(int a, int b)
{
    return a * b;
}

int main()
{
    int a = 10, b = 5;
    // 初始化结构体
    struct prt_fn pfn = { add, sub, mult };

    printf("a + b = %d\n", pfn.add(a, b));
    printf("a - b = %d\n", pfn.sub(a, b));
    printf("a * b = %d\n", pfn.mult(a, b));
    return 0;
}
#endif

#if 0
#include <stdint.h>
#define CRtcMaxSIZE 5
typedef struct{
		uint16_t Data[CRtcMaxSIZE];
		uint16_t front;
		uint16_t rear;
} RtcQueue;

RtcQueue park_rtc_buf;

void InitU16Que(void *q);
void entryItmU16Que(void *q,uint16_t e);
void exitItmU16Que(void *q,uint16_t *e);
int getLenU16Que(void *q); 
void getItmU16Que(void *q,uint16_t i,uint16_t* v);
//int GetU16ItmCount(void *q); 
int GetU16ItmCount(void); 


void InitU16Que(void *q)
{
    RtcQueue* pRtcQue=q;
	pRtcQue->front = pRtcQue->rear = 0;
}
void entryItmU16Que(void *q,uint16_t e)
{
	if((q->rear + 1) % GetU16ItmCount() == q->front)
	{
			q->front = (q->front + 1) % GetU16ItmCount();
	}
	q->Data[q->rear] = e;
	q->rear = (q->rear + 1) % GetU16ItmCount();
}
void exitItmU16Que(void *q,uint16_t *e)
{
	if(q->rear == q->front)
		return;
	*e = q->Data[q->front];
	q->front = (q->front + 1) % GetU16ItmCount();
}
void getItmU16Que(void *q,uint16_t i,uint16_t* v)
{
	uint16_t len;
	if(q->rear == q->front)
		return;
	len = (q->rear - q->front + GetU16ItmCount()) % GetU16ItmCount();
	if(len <= i) return;
	*v = q->Data[(q->front+i)% GetU16ItmCount()];
}
int getLenU16Que(void *q)
{
	return (q->rear - q->front + GetU16ItmCount()) % GetU16ItmCount();
}

//int GetU16ItmCount(void *q)
int GetU16ItmCount(void)
{
    return CRtcMaxSIZE;
    #if 0
    uint8_t u8offset;
    u8offset=offsetof( RtcQueue, front );
	uint8_t u8size;
    //u8size=sizeof(q->Data);
    u8size=sizeof(park_rtc_buf.Data);
    return u8size;
    //park_rtc_buf
	//return (q->rear - q->front + GetU16ItmCount()) % GetU16ItmCount();
    #endif
}

#endif

#if 0
#include <stdio.h>

//父结构体
struct father
{
    int f1;
    int f2;
};

//子结构体
struct son
{
    //子结构体里定义一个父结构体变量，必须放在子结构体里的第一位
    struct father fn;
    //子结构体的扩展变量
    int s1;
    int s2;

    //struct father fn;
};

void test(struct son *t)
{
    //将子结构体指针强制转换成父结构体指针
    struct father *f = (struct father *)t;
    //打印原始值
    printf("f->f1 = %d\n",f->f1);
    printf("f->f2 = %d\n",f->f2);
    //修改原始值
    f->f1 = 30;
    f->f2 = 40;
}

int main(void)
{
    struct son s;
    s.fn.f1 = 10;
    s.fn.f2 = 20;

    test(&s);
    //打印修改后的值
    printf("s.fn.f1 = %d\n",s.fn.f1);
    printf("s.fn.f2 = %d\n",s.fn.f2);

    return 0;
}
#endif


#if 1
#include <stdio.h>

#include <stdint.h>



//父结构体
struct father
{
    int f1;
    int f2;
};
//子结构体
struct son
{
    //子结构体里定义一个父结构体变量，必须放在子结构体里的第一位
    struct father fn;
    //子结构体的扩展变量
    int s1;
    int s2;

    //struct father fn;
};

void test(struct son *t)
{
    //将子结构体指针强制转换成父结构体指针
    struct father *f = (struct father *)t;
    //打印原始值
    printf("f->f1 = %d\n",f->f1);
    printf("f->f2 = %d\n",f->f2);
    //修改原始值
    f->f1 = 30;
    f->f2 = 40;
    //park_rtc_buf.pData=&RtcData[0];

}

int main(void)
{
    struct son s;
    s.fn.f1 = 10;
    s.fn.f2 = 20;

    test(&s);
    //打印修改后的值
    printf("s.fn.f1 = %d\n",s.fn.f1);
    printf("s.fn.f2 = %d\n",s.fn.f2);

    return 0;
}
#endif



